import 'package:demo/component/component_button.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:demo/views/mine/mine_nickname_controller.dart';

// 设置昵称
class MineNicknameView extends GetView<MineNicketnameController> {
  // 路由地址
  static const String routeName = '/mine_nickname';
  const MineNicknameView({super.key});

  @override
  Widget build(BuildContext context) {
    Get.lazyPut(() => MineNicketnameController());
    return Scaffold(
      resizeToAvoidBottomInset: false,
      appBar: AppBar(
        title: const Text('修改昵称'),
      ),
      body: Column(
        children: [
          _buildNickname(),
          _buildSubmit(),
        ],
      ),
    );
  }

  // 昵称
  _buildNickname() {
    return Padding(
      padding: const EdgeInsets.all(12),
      child: TextField(
        maxLength: 15,
        controller: controller.nicknameController,
        decoration: const InputDecoration(
          hintText: '请输入昵称',
        ),
      ),
    );
  }

  _buildSubmit() {
    return ComponentButton(
      label: '提  交',
      onTap: () {
        // 校验
        _checkNickname();
        // 提交
        controller.submit();
      },
    );
  }

  // 校验
  _checkNickname() {
    var nickname = controller.nicknameController.text.trim();
    if (nickname.isEmpty) {
      throw Exception('请输入昵称');
    }
  }
}
